import 'dart:async';
import '../../utils/auth.dart';
import '../web3_js_call.dart';

abstract class ChainCore {
  generateCallback<T>(Completer<T> completer, {bool showError = true}) {
    return JsCallback(
        callback: (result) {
          completer.complete(result);
        },
        errorCallback: (error) {
          completer.completeError(error);
        },
        showError: showError);
  }

  generateFuture<T>(int requestId, Completer<T> completer,
      {int timeoutSeconds = 10}) {
    return completer.future.timeout(Duration(seconds: timeoutSeconds),
        onTimeout: () {
      Web3JsCall().removeRequestId(requestId);
      return Future.error('operate timeout');
    });
  }

  Future<bool> localAuth() {
    return Authentication().startLocalAuth(showPasswordError: false);
  }
}


enum TransactionFunc {
  transfer,
  approve,
  setApproveForAll,
  addLiquidity,
  swapExactTokensForTokens,
  swapExactTokensForTokensSupportingFeeOnTransferTokens
}